import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/rendering.dart';

class IntoAppPage extends StatefulWidget {
  IntoAppPage({Key key}) : super(key: key);

  @override
  _IntoAppPageState createState() => _IntoAppPageState();
}

class _IntoAppPageState extends State<IntoAppPage> {
  Timer _timer;
  int count =3;

  @override
  void initState() {
    super.initState();
    StartTime();
  }

  StartTime() async {
    //设置启动图生效时间
    var _duration = new Duration(seconds: 1);
    new Timer(_duration, () {
      //空等1秒之后再计时
      _timer = new Timer.periodic(Duration(milliseconds: 1000), (v) {
        count--;
        if (count == 0) {
          navigationPage();
        } else {
          setState(() {});
        }
      });
      return _timer;
    });
  }

  void navigationPage() {
    _timer.cancel();
    //跳转到登录页面
    Navigator.of(context).pushReplacementNamed('/login');
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      //右上角对齐
      alignment: Alignment(1.0, -1.0),
      children: <Widget>[
        ConstrainedBox(
          constraints: BoxConstraints.expand(),
          child: Image.asset('images/dd.jpg', fit: BoxFit.cover),
        
         
            
        ),
        Padding(
          //left, top, right, bottom   左上右下
          padding: EdgeInsets.fromLTRB(0.0, 30.0, 10.0, 0.0),
          child: FlatButton(
            onPressed: () {
              navigationPage();
            },
            color: Colors.grey,
            child: Text(
              "$count 跳过广告",
              style: TextStyle(color: Colors.white, fontSize: 12.0),
            ),
          ),
        )
      ],
    );
  }
}
